public class Solution845 {
    public int longestMountain(int[] arr) {
        int c=0;
        int ans=0;
        while (c<arr.length-1){
            while (c<arr.length-1 && arr[c]>=arr[c+1]){
                c++;
            }
            if (c==arr.length-1){
                break;
            }
            int f=c;
            while (c<arr.length-1 && arr[c]<arr[c+1]){
                c++;
            }
            if (c==arr.length-1){
                break;
            }
            int g=c;
            while (c<arr.length-1 && arr[c]>arr[c+1]){
                c++;
            }
            if (g==c){
                continue;
            }
            ans=Math.max(ans,c-f+1);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution845().longestMountain(new int[]{2,1,4,7,3,2,5}));
    }
}
